//
//  NRWSliderCollectionCell.m
//  NRWMall
//
//  Created by 邢毅 on 2018/6/11.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWSliderCollectionCell.h"
#import "ZPSlider.h"

@interface NRWSliderCollectionCell()

@property (strong, nonatomic) ZPSlider *slider;

@end

@implementation NRWSliderCollectionCell

- (void)setTitleArr:(NSArray<NSString *> *)titleArr firstSelectIndex:(NSInteger)first lastSelectIndex:(NSInteger)last {
    
    if (first == 0 && last == 0) {
        last = titleArr.count - 1;
    }
    
    [self.slider removeFromSuperview];
    self.slider = [[ZPSlider alloc] initWithFrame:CGRectMake(getAdaptationWidth(48), 17, SCREEN_WIDTH() - getAdaptationWidth(48) * 2, 40) sliderTitles:titleArr defaultFirstIndex:first defaultLastIndex:last sliderImage:getImage(@"icon_slider")];
    [self.contentView addSubview:_slider];
    
    MJWeakSelf
    self.slider.block = ^(int firstIndexPath, int lastIndexPath) {
        
        if ([weakSelf.delegate respondsToSelector:@selector(sliderCollectionCell:withFirstIndexPath:lastIndexPath:)]) {
            
            [weakSelf.delegate sliderCollectionCell:weakSelf withFirstIndexPath:firstIndexPath lastIndexPath:lastIndexPath];
        }
    };
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = self.contentView.backgroundColor = getColor(@"#F9F9F9");;
        self.opaque = self.contentView.opaque = YES;
    }
    return self;
}

@end
